home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 43 / Amiga Format CD43 (1999)(Future Publishing)(GB)(Track 1 of 2)[!][issue 1999-09].iso / -serious- / archivers / xpk / xpk_source / xpkmaster / fault.c < prev    next >
C/C++ Source or Header  |  1999-06-14  |  2KB  |  85 lines

  1. #ifndef XPKMASTER_FAULT_C
  2. #define XPKMASTER_FAULT_C
  3.  
  4. /* Routinesheader
  5.  
  6.     Name:        fault.c
  7.     Main:        xpkmaster
  8.     Versionstring:    $VER: fault.c 1.7 (09.05.1998)
  9.     Author:        SDI
  10.     Distribution:    Freeware
  11.     Description:    Error message generators
  12.  
  13.  1.0   05.10.96 : first real version
  14.  1.1   27.12.96 : added parts of Fault functions
  15.  1.2   28.12.96 : finished the two Fault functions
  16.  1.3   31.03.97 : added new error (XPKERR_UNKNOWN);
  17.  1.4   02.04.97 : renamed to fault.c, removed geterror
  18.  1.5   21.02.98 : uses new style register definition
  19.  1.6   26.03.98 : some optimizations and a bug fix
  20.  1.7   09.05.98 : bug fix
  21. */
  22.  
  23. #include <proto/exec.h>
  24. #include <proto/dos.h>
  25. #include "xpkmaster.h"
  26. #include "texts.h"
  27.  
  28. ASM(BOOL) LIBXpkPrintFault(REG(d0, LONG code), REG(a0, STRPTR header))
  29. {
  30.   STRPTR a[2], fmt = "%s: %s\n";
  31.  
  32.   if(code > 0 || code < MINERROR)
  33.     code = XPKERR_UNKNOWN;
  34.  
  35.   a[1] = XpkErrs[-code];
  36.  
  37.   if(!(a[code = 0] = header))
  38.   {
  39.     ++code; fmt += 4;
  40.   }
  41.  
  42.   if(VPrintf(fmt, &a[code]) == -1)
  43.     return 0;  /* error */
  44.   else
  45.     return -1; /* ok */
  46. }
  47.  
  48. ASM(ULONG) LIBXpkFault(REG(d0, LONG code), REG(a0, STRPTR header),
  49.     REG(a1, STRPTR buffer), REG(d1, ULONG size))
  50. {
  51.   ULONG ssize = 0;
  52.  
  53.   if(size > 1 && buffer)
  54.   {
  55.     STRPTR string;
  56.  
  57.     if(code > 0 || code < MINERROR)
  58.       code = XPKERR_UNKNOWN;
  59.  
  60.     string = XpkErrs[-code];
  61.  
  62.     if((ssize = strlen(string)) > --size) /* remove 1 for 0-byte from size */
  63.       ssize = size;
  64.     size -= ssize;
  65.  
  66.     if(header && (code = strlen(header)) + 2 <= size)
  67.     {
  68.       CopyMem(header, buffer, code);
  69.       buffer[code++] = ':';
  70.       buffer[code++] = ' ';
  71.       buffer += code;
  72.     }
  73.     else
  74.       code = 0;
  75.  
  76.     CopyMem(string, buffer, ssize);
  77.     buffer[ssize] = 0;
  78.     ssize += code;
  79.   }
  80.  
  81.   return ssize;
  82. }
  83.  
  84. #endif /* XPKMASTER_FAULT_C */
  85.